<!--
 * @Author: koppie
 * @Date: 2021-05-07 15:15:22
 * @LastEditTime: 2021-05-07 15:15:30
 * @LastEditors: koppie
 * @Description: 
 * @FilePath: /bigscreen/src/pages/ytScreen/components/clock.vue
-->
<template>
	<div>{{ newTime }}</div>
</template>

<script>
let icnow = new Date() // 初始化时间
let interval // 定义全局定时器，用于清除定时器
export default {
	name: 'app',
	data() {
		return {
			year: icnow.getFullYear(),
			month: icnow.getMonth() + 1,
			date: icnow.getDate(),
			time: icnow.toTimeString().substring(0, 8),
		}
	},
	mounted() {
		interval = setInterval(() => {
			let icnow = new Date()
			this.year = icnow.getFullYear()
			this.month = icnow.getMonth() + 1
			this.date = icnow.getDate()
			this.time = icnow.toTimeString().substring(0, 8)
		}, 1000)
	},
	computed: {
		// 当前时间
		newTime: function () {
			return this.year + '年' + this.month + '月' + this.date + '日' + ' ' + this.time
		},
	},
	beforeDestroy() {
		clearInterval(interval)
	},
}
</script>
